export function login(username: string, password: string) {
  return request.post('/user/login', {
    username,
    password,
  })
}

export function logoutAPI() {
  return request.post('/user/logout')
}

interface RegisterUser {
  username: string
  password: string
  phoneNumber: string
  email: string
}

export function register(user: RegisterUser) {
  return request.post('/user/register', {
    username: user.username,
    password: user.password,
    email: user.email,
    phoneNumber: user.phoneNumber,
  })
}

export function getUserInfo(username: string) {
  return request.get(`/user/info?username=${username}`)
}

export function checkLogin(userId: any) {
  return request.get(`/checkLogin?userId=${userId}`)
}

/**
 * 头像上传
 */
export function uploadAvatar(data: any) {
  return request.post('/uploadAvatar', {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data,
  })
}

export function updateUserInfo(user: any) {
  return request.put(`/user/info`, {
    id: user.id,
    avatar: user.avatar,
    email: user.email,
    nickName: user.nickName,
    phoneNumber: user.phoneNumber,
    sex: user.sex,

  })
}

export function updateUserPassword(userId: number, password: string) {
  return request.put(`/user/pwd`, {
    id: userId,
    password,

  })
}
